package com.wt.admin.service.ai.impl.agents;

import cn.hutool.json.JSONUtil;
import com.wt.admin.domain.dto.ai.AgentsInfoDTO;
import com.wt.admin.domain.entity.ai.MCPEntity;
import com.wt.admin.domain.entity.ai.ModelConfigEntity;
import com.wt.admin.service.ai.impl.mcp.MCPStart;
import org.springframework.ai.tool.ToolCallbackProvider;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public interface AgentsBuilderService {


    AgentsManager.Agent builder(AgentsInfoDTO agents, ModelConfigEntity model, List<MCPEntity> mcpEntities);


    default List<ToolCallbackProvider> getToolCallbackProvider(MCPStart mcpStart, List<MCPEntity> mcpEntities){
        List<ToolCallbackProvider> list = new ArrayList<>();
        mcpEntities.forEach(i -> {
            switch (i.getTag()) {
                case 0 -> {
                    ToolCallbackProvider toolCallbackProvider =
                            mcpStart.builderMcpClientSTDIO(i.getContent(), i.isSync());
                    list.add(toolCallbackProvider);
                }
                case 1 ->
                        JSONUtil.toList(i.getContent(), Map.class).forEach(k -> {
                            ToolCallbackProvider toolCallbackProvider =
                                    mcpStart.builderMcpClientSSE(k.get("server").toString(), k.get("url").toString(), i.isSync());
                            list.add(toolCallbackProvider);
                        });
                case 2 ->
                        JSONUtil.toList(i.getContent(), Map.class).forEach(k -> {
                            ToolCallbackProvider toolCallbackProvider =
                                    mcpStart.builderMcpClientFlux(k.get("server").toString(), k.get("url").toString(), i.isSync());
                            list.add(toolCallbackProvider);
                        });
            }
        });
        return list;
    }

}
